<script type="text/javascript">
$(document).ready(function() {
    var data = JSON.parse($(".s_temple_setting.class_data_settings").html());
    $(".s_s_a_unreply_apply").hide();
    $("#s_s_a_unreply_apply_info").hide();
    $("#form_class_apply").hide();
    $("#s_s_c_classRadioTemple").hide();
    $(".s_s_a_select_class").hide();
    $(".s_s_c_students").hide();
    $("#studentlist_temple").hide();
    if(data.op==3){
    	s_s_c_addClasses(data.classlist);
    	$("#form_class_apply").show();
    	$(".s_s_a_select_class").show();
    }
    if(data.op==1){
   	 $("#s_s_a_unreply_apply_info").show();
  	  $(".s_s_a_unreply_apply").show();
  	  $("#form_class_apply").hide();
  	  $("#s_s_c_classRadioTemple").hide();
  	  $(".s_s_a_select_class").hide();
  	  $(".s_classid").html(data.applydata.classdata.classid);
  	  $(".s_classname").html(data.applydata.classdata.displayname);
  	  $(".s_class_introduce").html(data.applydata.classdata.description);
  	  $(".s_class_master").html("").append($("<a>").attr("href",getHomeURL(data.applydata.classdata.master)).html(data.applydata.master.name));
    }
    if(data.op==2){
    	 $("#s_s_a_unreply_apply_info").show();
    	  $(".s_classid").html(data.classdata.classid);
      	  $(".s_classname").html(data.classdata.displayname);
      	  $(".s_class_introduce").html(data.classdata.description);
      	  $(".s_class_master").html("").append($("<a>").attr("href",getHomeURL(data.master.uid)).html(data.master.name));
      	   $(".s_s_c_students").show();
 		$.each(data.students,function(k,v){
 			s_s_aaddStudent(v);
 		});
		console.log(data);
    }
    bindAjaxForm($("#form_class_apply"),s_s_c_onSuccess,s_s_c_onError,"di");
});

function s_s_c_onSuccess(data) {
    console.log(data);
    s_s_c_operatedone(data.code, data.message, data.data);
}
function s_s_c_onError(data) {
    s_s_c_operatedone( - 101, "服务器返回了未知的数据，请上报管理员", data.responseText);
}
function s_s_c_operatedone(id, message, data) {
    if (id == -101) {
        showMessage("s_s_c_message", -101, message + "<br><br><pre>" + data + "</pre>");
        return;
    }
    if (id != 0 && id != 3) {
        showMessage("s_s_c_message", id, message);
    }
    if (id == 0) {
        showMessage("s_s_c_message", id, message);
    }
    if(data.op=="showDetial"){
        console.log(data);
    	  $("#s_s_a_unreply_apply_info").show();
    	  $(".s_s_a_unreply_apply").show();
    	  $("#form_class_apply").hide();
    	  $("#s_s_c_classRadioTemple").hide();
    	  $(".s_s_a_select_class").hide();
    	  $(".s_classid").html(data.applydata.classdata.classid);
    	  $(".s_classname").html(data.applydata.classdata.displayname);
    	  $(".s_class_introduce").html(data.applydata.classdata.description);
    	  $(".s_class_master").html("").append($("<a>").attr("href",getHomeURL(data.applydata.classdata.master)).html(data.applydata.master.name));
   }
}
function s_s_c_addClasses(data){
	$.each(data,function(k,v){
		s_s_c_addClasses_year(k,v);
	});
}
function s_s_c_addClasses_year(key,value){
	var div = $("<div class='inline fields'>");
	div.append($("<label for='classid'>").html(key+"级"));
	$.each(value,function(k,v){
		div.append(s_s_c_getClassRadio(v));
	});
	$("#form_class_apply").prepend(div);
}
function s_s_c_getClassRadio(v){
	var $tmp = $("#s_s_c_classRadioTemple").clone();
	$tmp.attr("id","");
	$tmp.show();
	$tmp.find(".s_s_c_classid").attr("value",v.classid);
	$tmp.find(".s_s_c_classname").html(v.displayname);
	return $tmp;
}
function s_s_aaddStudent(data){
	var $tmp = $("#studentlist_temple").clone();
	$tmp.show();
	$tmp.attr("id","s_stu_"+data.uid);
	$tmp.find(".s_name").html(data.card.name).attr("href",getHomeURL(data.card.uid));
	$tmp.find(".s_stuid").html(data.stuid);
	$tmp.find(".s_uid").attr("uid",data.card.uid);
	$tmp.find(".s_head").attr("src",data.card.head_image_path);
	$tmp.find(".s_subject").html(data.displayname);
	$tmp.find(".s_motto").html(data.card.motto);
	$("#s_s_c_student_list").append($tmp);
}
</script>
<h2>学生班级信息</h2>
<div class="s_temple_setting class_data_settings"><?php print_json_setting("class_data_settings");?></div>
<div class="ui message hidden" id="s_s_c_message"></div>
<div class="ui warning message s_s_a_unreply_apply">
	<div class="header">您的申请暂未得到管理员批复</div>
	请耐心等待，下面是您所申请班级的基本信息
</div>
<table class="ui unstackable table" id="s_s_a_unreply_apply_info">
	<thead>
		<tr>
			<th>基本信息</th>
			<th></th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td>班级id</td>
			<td class="s_classid">empty</td>
		</tr>
		<tr>
			<td>班级名称</td>
			<td class="s_classname">empty</td>
		</tr>
		<tr>
			<td>班级介绍</td>
			<td class="s_class_introduce">empty</td>
		</tr>
		<tr>
			<td>班主任</td>
			<td class="s_class_master">empty</td>
		</tr>
	</tbody>
</table>
<div class="ui warning message s_s_a_select_class">
	<div class="header">你还未选择你的班级</div>
	请在这里选择你的班级
</div>
<form class="ui form" url="index.php?mod=home&childmod=setting&ajax=ture&op=class_apply" id="form_class_apply">
	<hr>
	<div class="field">
		<div class="ui left icon input fluid">
			<input type="text" name="note" placeholder="审核留言">
			<i class="users icon"></i>
		</div>
	</div>
	<hr>
	<button class="ui button submit" type="submit">提交</button>
</form>
<div class="field" id="s_s_c_classRadioTemple">
	<div class="ui radio checkbox">
		<input type="radio" class="s_s_c_classid" name="classid" class="hidden">
		<label class="s_s_c_classname"></label>
	</div>
</div>
<div class="s_s_c_students">
	<h4 class="ui dividing header">学生列表</h4>
	<div class="ui middle relaxed aligned divided list" id="s_s_c_student_list"></div>
	<div class="item" id="studentlist_temple">
		<img class="ui avatar image s_head" src="">
		<div class="content s_description">
			<a class="s_name"></a>
			<div class="extra text s_motto"></div>
		</div>
		
	</div>
</div>